import { TornaLoginData } from "../types/type";
import { TornaHttp } from "./torna";

/**
 * 登录参数
 * @date 1/24/2024 - 6:17:26 PM
 *
 * @export
 */
export type JsonParams = {
  /**
   * 账号
   * @date 1/24/2024 - 6:17:08 PM
   *
   * @type {string}
   */
  username: string,
  
  /**
   * 密码
   * @date 1/24/2024 - 6:17:14 PM
   *
   * @type {string}
   */
  password: string,
};


/**
 * 登录Torna后台
 * @date 1/24/2024 - 6:16:51 PM
 *
 * @export
 * @async
 * @param {string} url
 * @param {JsonParams} json 登录参数
 * @param {?AbortController} [canceller]
 * @returns {Promise<TornaLoginData>}
 */
export async function login(url: string, json: JsonParams, canceller?: AbortController): Promise<TornaLoginData> {
  const { data } = await TornaHttp.fetch<TornaLoginData, never, JsonParams>(url, { method: 'POST', json, ...canceller });
  return data;
}